home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / blurb_20.zip / BLURB.BAK next >
Text File  |  1992-04-18  |  18KB  |  602 lines

  1. //--------------------------------BLURB.CPP---------------------------------
  2. //
  3. //  Blurb v2.0  This is the updated version of the fortune program.
  4. //
  5. //--------------------------------------------------------------------------
  6. //
  7. //                                 Notice:
  8. //
  9. //                      Confidential and Proprietary
  10. //
  11. //  This work contains valuable confidential and proprietary information.
  12. //  Disclosure, use or reproduction without the written authorization from
  13. //  Jon Privatt is prohibited.  This unpublished work by Jon Privatt is
  14. //  protected by the laws of the United States and other countries.
  15. //
  16. //  If publication of the work should occur the following notice shall apply:
  17. //
  18. //  "Copyright (c) 1992, Jon Privatt, All Rights Reserved"
  19. //
  20. //--------------------------------------------------------------------------
  21.  
  22. #include <time.h>
  23. #include <stdio.h>
  24. #include <dos.h>
  25. #include <conio.h>
  26. #include <dir.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <io.h>
  30. #include <ctype.h>
  31.  
  32.  
  33. //===========================COMPILER DEFINITIONS===========================
  34.  
  35.  
  36. //===============================GLOBAL TYPES===============================
  37.  
  38.  
  39. //=============================GLOBAL VARIABLES=============================
  40. char  ch,
  41.       *p,
  42.       *q,
  43.       outlines[26][134],
  44.       blurb[1001];                // blurb input.
  45.  
  46. unsigned long
  47.       choice,
  48.       next=0,
  49.       num;                     // number of blurbs
  50.  
  51. unsigned seed=0;
  52.  
  53. time_t first, second;
  54. long curpos;
  55.  
  56. int   x=2,                     // current x position
  57.       y=1,                     // current y position
  58.       n=0,                     // position within blurb string!
  59.       delayvalue=50,
  60.       length,
  61.       aa=2,
  62.       lines,
  63.       words,                   // number of words in the blurb.
  64.       mxx,                     // maximum x position
  65.       mxy,                     // maximum y position
  66.       bcolor=9,                // background color
  67.       fcolor=15;               // foreground color
  68.  
  69. struct ftime
  70.       fnow,                    // time/date of last reindex
  71.       fthen;                   // time/date now
  72.  
  73. struct text_info
  74.       ti;
  75.  
  76. enum BOOLEAN {false, true}
  77.       quit=false,
  78.       end=false,
  79.       displayblurb=true,
  80.       mixup=false,
  81.       inorder=false,
  82.       autodelay=false,
  83.       border=true,
  84.       hide=false,               // hide the author line.  Alters aa=0
  85.       ERROR=false,              // error, Blurb renamed or altered if ==true.
  86.       codes=true;
  87.  
  88. FILE *blurbs,                   // file containing the blurbs
  89.      *cfg,                      // file containing configuration info.
  90.      *idx;                      // index file to blurbs
  91.  
  92.  
  93. //----------------------------------title------------------------------------
  94. void title() {
  95.   //Prints "Blurb v2.0"...encoded to prevent alteration.
  96.   cprintf("%c%c%c%c%c%c%c%c%c%c",66,108,117,114,98,32,118,50,46,48);
  97.  
  98.   gotoxy((mxy-18),1);
  99.   //Prints "Jon Privatt (c)1992"...encoded to prevent alternation.
  100.   cprintf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",74,111,110,32,80,114,105,118,97,116,116,32,40,99,41,49,57,57,50);
  101.   }
  102.  
  103. //--------------------------------get_cfg-----------------------------------
  104. int get_cfg() {
  105.  
  106.   p=searchpath("blurb.cfg");
  107.   if((cfg=fopen(p,"rb"))==NULL) return 1;
  108.  
  109.   fseek(cfg,39,SEEK_SET);              // position past file header.
  110.  
  111.   fread(&num, sizeof(unsigned long), 1, cfg);
  112.   fread(&border, sizeof(BOOLEAN), 1, cfg);
  113.   fread(&hide,sizeof(BOOLEAN),1,cfg);
  114.   fread(&bcolor, sizeof(int), 1, cfg);
  115.   fread(&fcolor, sizeof(int), 1, cfg);
  116.   fread(&delayvalue, sizeof(int), 1, cfg);
  117.   fread(&codes,sizeof(BOOLEAN),1,cfg);
  118.   fread(&autodelay,sizeof(BOOLEAN),1,cfg);
  119.   fread(&fthen, sizeof(fthen), 1, cfg);
  120.   fread(&next, sizeof(unsigned long), 1, cfg);
  121.   fread(&inorder,sizeof(BOOLEAN),1,cfg);
  122.   fread(&seed,sizeof(seed),1,cfg);
  123.   fclose(cfg);
  124.   return 0;
  125. }
  126.  
  127.  
  128. //-------------------------------save_cfg-----------------------------------
  129. void save_cfg() {
  130.   int yyyy;
  131.  
  132.   p=searchpath("blurb.cfg");
  133.   if (p==NULL) {                  // file not in path. Create new one
  134.     q=searchpath("blurb.exe");    //   wherever blurb.exe is located.
  135.     yyyy=strlen(q)-3;
  136.     q[yyyy++]='c';
  137.     q[yyyy++]='f';
  138.     q[yyyy]='g';
  139.       if ((cfg=fopen(q,"w+b"))==NULL) {
  140.       printf("Unable to create BLURB.CFG\n");
  141.       exit(1);
  142.       }
  143.     }
  144.     else {
  145.       if((cfg=fopen(p,"w+b"))==NULL) {
  146.     printf("Unable to create BLURB.CFG\n");
  147.     exit(1);
  148.     }
  149.       }
  150.   fputs("Blurb version 2.0\r\nConfiguration File\n",cfg); // File header.
  151.   fputc(26,cfg);                                          // EOF mark.
  152.   fwrite(&num, sizeof(unsigned long), 1, cfg);
  153.   fwrite(&border, sizeof(BOOLEAN), 1, cfg);
  154.   fwrite(&hide,sizeof(BOOLEAN),1,cfg);
  155.   fwrite(&bcolor, sizeof(int), 1, cfg);
  156.   fwrite(&fcolor, sizeof(int), 1, cfg);
  157.   fwrite(&delayvalue, sizeof(int), 1, cfg);
  158.   fwrite(&codes,sizeof(BOOLEAN),1,cfg);
  159.   fwrite(&autodelay,sizeof(BOOLEAN),1,cfg);
  160.   fwrite(&fthen, sizeof(fthen), 1, cfg);
  161.   fwrite(&next, sizeof(unsigned long),1,cfg);
  162.   fwrite(&inorder, sizeof(BOOLEAN), 1, cfg);
  163.   fwrite(&seed,sizeof(seed),1,cfg);
  164.   fclose(cfg);
  165. }
  166.  
  167. //------------------------------reindex-----------------------------------
  168. void reindex() {
  169.   long fl;                           // total length of the file.
  170.   long temp, percent, prev=-1;
  171.   int yyyy;
  172.  
  173.   num=1;
  174.   textcolor(7);
  175.   textbackground(0);
  176.   clrscr();
  177.   title();
  178.   gotoxy(1,3);
  179.   cprintf("%clurbs has been altered.  %cuto-%ceindex %cngaged...",66,65,82,69);
  180.   p=searchpath("blurbs");
  181.   if((blurbs=fopen(p,"rt"))==NULL) {
  182.     printf("Unable to find BLURBS\n");
  183.     exit(1);
  184.     }
  185.   p=searchpath("blurb.idx");
  186.   if (p==NULL) {                  // file not in path. Create new one
  187.     q=searchpath("blurb.exe");    //   wherever blurb.exe is located.
  188.     yyyy=strlen(q)-3;
  189.     q[yyyy++]='i';
  190.     q[yyyy++]='d';
  191.     q[yyyy]='x';
  192.     if ((idx=fopen(q,"w+b"))==NULL) {
  193.       printf("Unable to create BLURB.IDX\n");
  194.       fclose(blurbs);
  195.       exit(1);
  196.       }
  197.     }
  198.   else {
  199.     if((idx=fopen(p,"w+b"))==NULL) {
  200.       printf("Unable to create BLURB.IDX\n");
  201.       fclose(blurbs);
  202.       exit(1);
  203.       }
  204.     }
  205.   fseek(blurbs,0L,SEEK_END);
  206.   fl=ftell(blurbs);
  207.   gotoxy(1,4);
  208.   printf("%ceindexing:",82);
  209.   if (fl>100) temp=fl/100;
  210.   else percent=50;
  211.   rewind(blurbs);
  212.   curpos=ftell(blurbs);                 // write first record.
  213.   fwrite(&curpos,sizeof(long),1,idx);
  214.   while (fgets(blurb,1000,blurbs)!=NULL) {
  215.     num++;
  216.     curpos=ftell(blurbs);
  217.     if (fl>100) percent=curpos/temp;
  218.     if (percent!=prev) {
  219.       gotoxy(13,4);
  220.       prev=percent;
  221.       printf("%ld%%",percent);
  222.       }
  223.     fwrite(&curpos, sizeof(long), 1, idx);
  224.     }
  225.   gotoxy(13,4);
  226.   printf("100%%");
  227.   gotoxy(1,5);
  228.   printf("%lu BLURBS now indexed for maximum speed.\n",(num-1));
  229.   displayblurb=false;
  230.   fclose(idx);
  231.   getftime(fileno(blurbs),&fthen);
  232.   fclose(blurbs);
  233.   save_cfg();
  234. }
  235.  
  236.  
  237. //-------------------------------get_idx-----------------------------------
  238. void get_idx() {
  239.  
  240.   p=searchpath("blurbs");
  241.   if((blurbs=fopen(p,"rt"))==NULL) {  // check for updated BLURBS
  242.     printf("Unable to find BLURBS\n");
  243.     exit(1);
  244.     }
  245.   getftime(fileno(blurbs),&fnow);
  246.   fclose(blurbs);
  247.   if ((fnow.ft_tsec!=fthen.ft_tsec)||(fnow.ft_min!=fthen.ft_min)||(fnow.ft_hour!=fthen.ft_hour)||(fnow.ft_day!=fthen.ft_day)||(fnow.ft_month!=fthen.ft_month)||(fnow.ft_year!=fthen.ft_year))
  248.     reindex();
  249.  
  250.   p=searchpath("blurb.idx");
  251.   if((idx=fopen(p,"rb"))==NULL) reindex();
  252.   next++;
  253.   if (next>num) next=0;
  254.   if (inorder==true)
  255.     choice = next;
  256.   else
  257.     choice = (rand()%num);
  258.   curpos=(sizeof(long)*choice);
  259.   fseek(idx,curpos,SEEK_SET);
  260.   fread(&curpos,sizeof(long),1,idx);
  261.   fclose(idx);
  262.  
  263.   p=searchpath("blurbs");
  264.   if((blurbs=fopen(p,"rt"))==NULL) {
  265.     printf("Unable to find BLURBS\n");
  266.     exit(1);
  267.     }
  268.   fseek(blurbs,curpos,SEEK_SET);
  269.   fgets(blurb,1000,blurbs);
  270.   fclose(blurbs);
  271. }
  272.  
  273.  
  274. //----------------------------lin